
function ProbabilitiesManager:moveKeysAwayFromDoors()
	
	if gField.entityTypes.Key
	then
		for keyName, key in pairs(gField.entityTypes.Key) 
		do
			local relatedDoor = gField.entityTypes.Door[keyName]
			
			for possibleLocation, probability in pairs(key.locationStaticProbabilities) 
			do
				local distanceToLocation1 = possibleLocation.distanceToOtherLocations[relatedDoor.container1]
				local distanceToLocation2 = possibleLocation.distanceToOtherLocations[relatedDoor.container2]
				
				if distanceToLocation1 > distanceToLocation2 
				then
					key.locationStaticProbabilities[possibleLocation] = distanceToLocation1 * distanceToLocation1
				else
					key.locationStaticProbabilities[possibleLocation] = distanceToLocation2 * distanceToLocation2
				end 
			end
		end
	end
end

---

function ProbabilitiesManager:moveKeysAwayFromPlayer()

	local playerLocation = gPlayer.body:getCollapsedProperty("CurrentContainer")
	
	if gField.entityTypes.Key
	then
		for keyName, key in pairs(gField.entityTypes.Key) 
		do
			local relatedDoorCollapsed = not gField.entityTypes.Door[keyName]:hasUndeterminedSate()
			
			for possibleLocation, probability in pairs(key.locationStaticProbabilities) 
			do
				local newProbability = possibleLocation.distanceToOtherLocations[playerLocation]
				
				if newProbability 
				then
					if not relatedDoorCollapsed 
					then											-- we also try to see doors before keys
						newProbability = newProbability * 2
					else
						newProbability = newProbability / 2
					end
					
					key.locationDynamicProbabilities[possibleLocation] = newProbability * newProbability
				end
			end
		end
	end
end